import java.math.BigInteger;
import java.util.Objects;
import java.util.Scanner;

public class C_1582 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        BigInteger b = new BigInteger(sc.next());
        BigInteger bigInteger = new BigInteger("0");
        BigInteger num = new BigInteger("0");
        while (true){

            if (bigInteger.toString().contains("1")||bigInteger.toString().contains("2")){
                num = num.add(BigInteger.valueOf(1));
            }
            bigInteger = bigInteger.add(BigInteger.valueOf(1));
            if (Objects.equals(b, bigInteger)){
                break;
            }
        }
        if (0 > num.compareTo(BigInteger.valueOf(20123))){
            System.out.println(num);
        }else {
            System.out.println(num.divide(BigInteger.valueOf(20123)));
        }
    }

}
